//
//  MYShopDetailsSpecificationsCell.m
//  MuYing
//
//  Created by tbb on 2019/7/30.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYShopDetailsSpecificationsCell.h"

@interface MYShopDetailsSpecificationsCell () <UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView * specificationsCollView;
@end

@implementation MYShopDetailsSpecificationsCell

- (void)layoutSubviews {
    [super layoutSubviews];
    self.spuSaleAttrValueArray = NSMutableArray.new;
    [self.contentView addSubview:self.specificationsCollView];
}

#pragma mark -- lazy
-(UICollectionView *)specificationsCollView {
    if (!_specificationsCollView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _specificationsCollView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
        _specificationsCollView.backgroundColor =  UIColor.whiteColor;
        _specificationsCollView.delegate = self;
        _specificationsCollView.dataSource = self;
        _specificationsCollView.bounces = false;
        _specificationsCollView.contentInset = UIEdgeInsetsMake(0, 12, 0, 12);
        [_specificationsCollView registerNib:[UINib nibWithNibName:@"MYShopDetailsSpecificationsCollCell" bundle:nil] forCellWithReuseIdentifier:@"MYShopDetailsSpecificationsCollCell"];
    }
    return _specificationsCollView;
}
#pragma mark -- lazy end
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.spuSaleAttrValueArray.count;
}

- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    YQPSpuSaleAttrValueListModel *model = self.spuSaleAttrValueArray[indexPath.row];
    MYShopDetailsSpecificationsCollCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYShopDetailsSpecificationsCollCell" forIndexPath:indexPath];
    [cell setModel:model];
    return cell;
}
//设置头视图的尺寸，如果想要使用头视图，则必须实现该方法
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{

    return CGSizeMake(kScreenWidth, 77);

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(61,28);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 18.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 12;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    MYShopDetailsSpecificationsCollCell *cell = (MYShopDetailsSpecificationsCollCell *)[collectionView cellForItemAtIndexPath:indexPath];
//    cell.isCellSelect = YES;
}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
    MYShopDetailsSpecificationsCollCell *cell = (MYShopDetailsSpecificationsCollCell *)[collectionView cellForItemAtIndexPath:indexPath];
//    cell.isCellSelect = NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)setSpuSaleAttrValueList:(NSArray *)spuSaleAttrValueList
{
    _spuSaleAttrValueList = spuSaleAttrValueList;
    [self.spuSaleAttrValueArray removeAllObjects];
    [self.spuSaleAttrValueArray addObjectsFromArray:spuSaleAttrValueList];
    [self.specificationsCollView reloadData];
}
@end



